package cn.taobaoke.restful.domain;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

/**
 * @author bjyangzuo
 * @since 2017-04-18 20:31
 */
public interface DocumentRepository extends JpaRepository<DocumentEntity, Long> {

    @Query("from DocumentEntity entity where (entity.isDelete = null or entity.isDelete != true) and entity.id = :id and entity.domainId = :domainId")
    Optional<DocumentEntity> findById(@Param("id") Long documentId, @Param("domainId") Long domainId);

    @Query("from DocumentEntity entity where (entity.isDelete = null or entity.isDelete != true) and entity.domainId = :domainId ORDER BY entity.publishTime DESC")
    Page<DocumentEntity> findDocumentsByPage(@Param("domainId") Long domainId, Pageable pageable);
}
